const path = require('path');

// 引入插件  
const {CleanWebpackPlugin} = require('clean-webpack-plugin');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const CopyWebpackPlugin = require('copy-webpack-plugin');

module.exports = {
    // 环境配置：生产环境production、开发环境development
    mode:'none',
    // 入口文件
    entry:{
        index:'./src/js/index.js',
        select:'./src/js/select.js',
        voucher:'./src/js/voucher.js',
        information:'./src/js/imformation.js',
        record:'./src/js/record.js',
        api:'./src/js/api.js',
        require:'./src/js/request.js',
        promise:'./src/js/promise.js'
    },
    // 出口文件
    output:{
        path:path.join(__dirname,'dist'),
        filename:'js/[name].js',
    },
    module:{
        rules:[
            {
                test:/\.css$/,
                use:['style-loader','css-loader']
            },
            {
                test: /\.(png|jpg)$/,
                loader: 'url-loader',
                type: 'javascript/auto',//解决asset重复
                options: {
                    limit: 1 * 1024,
                    name:'[hash:10].[ext]',
                    outputPath:'imgs',
                    esModule:false,
                }
            },
            {
                test:/\.html$/,
                loader:'html-loader',
            },
            {
                exclude: /\.(html|js|css|less|sass|scss|jpg|jpeg|png|gif)$/,
                loader: 'file-loader',
                options: {
                  outputPath: 'media',
                  name: '[hash:10].[ext]',
                },
            },
            {
                test:/.js$/,
                use:{
                    loader:'babel-loader',
                    options:{
                        //要用到的这个loader的插件
                        // presets 你要使用的子插件
                        presets:['@babel/preset-env']
                    }
                }
            }
        ]
    },
    plugins: [
        new CleanWebpackPlugin(),
        new HtmlWebpackPlugin({
            template:'./src/index.html',
            filename:'index.html',
            chunks:['promise','index']
        }),
        new HtmlWebpackPlugin({
            template:'./src/select.html',
            filename:'select.html',
            chunks:['promise','select']
        }),
        new HtmlWebpackPlugin({
            template:'./src/voucher.html',
            filename:'voucher.html',
            chunks:['promise','voucher']
        }),
        new HtmlWebpackPlugin({
            template:'./src/information.html',
            filename:'information.html',
            chunks:['promise','information']
        }),
        new HtmlWebpackPlugin({
            template:'./src/record.html',
            filename:'record.html',
            chunks:['record']
        }),
        new CopyWebpackPlugin({
            patterns:[
                {
                    from:'./src/public',
                    to:'./public',
                }
            ]
        })
    ],
    // await在顶层使用时使模块成为异步模块。experiments.futureDefaults设置为时默认启用true。
    experiments: {
        futureDefaults: true,
    }
}